<?php
/*
File: stats_sppc.php
Version: 2.0
Date created: 
Last Edited : 26-07-2008
Author: Craig G Smith<craig@joomla-host.co.za
*/

  defined( 'JOSCOM_VERSION' ) or die( 'Direct Access to this location is not allowed.' );
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      tep_db_connect() or die('Unable to connect to database server!');
    }
    global $category_links, $languages_id, $cPath, $cPath_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    require(DIR_WS_COMPONENT . 'includes/application_top.php');
  }

?>
<link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_COMPONENT ?>includes/stylesheet.css">
<script language="javascript" src="<?php echo DIR_WS_COMPONENT ?>includes/general.js"></script>
<body onLoad="SetFocus();">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
	  			                  <input type="hidden" name="by" value="<?php echo $_REQUEST['by']?>">
          </form>
  <tr class="dataTableRow" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)"> <td class="maincol">
		<table border="0" width="60%">
		<tr><td><b>Order By : </b></td>
		<td class="dataTableContent"><a href=<?php echo tep_href_link(FILENAME_REPORT_SPPC, tep_get_all_get_params(array('by')).'&by=productsname', 'SSL') ?>>Product Name</a></td>
		<td class="dataTableContent"><a href=<?php echo tep_href_link(FILENAME_REPORT_SPPC, tep_get_all_get_params(array('by')).'&by=companyname', 'SSL') ?>>Company Name</a></td></tr>
		</table></td></tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="1" class="adminlist"><thead>
              <tr class="dataTableHeadingRow">
                <th class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_COMPANYNAME; ?></td>
                <th class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_NAME; ?>&nbsp;</td>
                <th class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_GROUPNAME; ?>&nbsp;</td>
                <th class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_CATEGORYNAME; ?>&nbsp;</td>
                <th class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_PRODUCTNAME; ?>&nbsp;</td>												
                <th class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_PRODUCTDESC; ?>&nbsp;</td>
				<th class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_PRODUCTMODEL; ?>&nbsp;</td>
                <th class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_REGULARPRICE; ?>&nbsp;</td>
                <th class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_SPECIALPRICE; ?>&nbsp;</td>

                <th class="dataTableHeadingContent" align="right">&nbsp;</td>
              </tr>
</thead>
			  
			       <tr class="dataTableRow" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)">
                <td class="dataTableContent" width="15%"><?php echo TABLE_TOTAL_SPECIALPRICE; ?></td>
                <td class="dataTableContent" align="right" width="15%"><?php 
                $m = 0;
                $specials_sql = "SELECT ". TABLE_ADDRESS_BOOK .".entry_company, " . TABLE_CUSTOMERS . ".customers_firstname, " . TABLE_CUSTOMERS . ".customers_lastname, " . TABLE_CUSTOMERS_GROUPS . ".customers_group_name, " . TABLE_CATEGORIES_DESCRIPTION . ".categories_name, " . TABLE_PRODUCTS_DESCRIPTION . ".products_name, " . TABLE_PRODUCTS_DESCRIPTION . ".products_description, " . TABLE_PRODUCTS . ".products_model, " . TABLE_PRODUCTS . ".products_price, " . TABLE_PRODUCTS_GROUPS . ".customers_group_price
FROM ((((((" . TABLE_CUSTOMERS . " INNER JOIN " . TABLE_CUSTOMERS_GROUPS ." ON " . TABLE_CUSTOMERS . ".customers_group_id = " . TABLE_CUSTOMERS_GROUPS . ".customers_group_id) INNER JOIN " . TABLE_PRODUCTS_GROUPS . " ON " . TABLE_CUSTOMERS_GROUPS . ".customers_group_id = " . TABLE_PRODUCTS_GROUPS . ".customers_group_id) INNER JOIN ". TABLE_PRODUCTS ." ON " . TABLE_PRODUCTS_GROUPS . ".products_id = " . TABLE_PRODUCTS . ".products_id) INNER JOIN " . TABLE_PRODUCTS_DESCRIPTION . " ON " . TABLE_PRODUCTS . ".products_id = " . TABLE_PRODUCTS_DESCRIPTION . ".products_id) INNER JOIN ". TABLE_PRODUCTS_TO_CATEGORIES . " ON " . TABLE_PRODUCTS . ".products_id = " . TABLE_PRODUCTS_TO_CATEGORIES . ".products_id) INNER JOIN " . TABLE_ADDRESS_BOOK ." ON " . TABLE_CUSTOMERS . ".customers_id = " . TABLE_ADDRESS_BOOK . ".customers_id) INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " ON " . TABLE_PRODUCTS_TO_CATEGORIES . ".categories_id = " . TABLE_CATEGORIES_DESCRIPTION . ".categories_id
ORDER BY " . TABLE_ADDRESS_BOOK . ".entry_company";
                $specials_qry = tep_db_query($specials_sql);
                while ($mcount = tep_db_fetch_array($specials_qry)) {
                 $m++;
                }
               print max($m,0);
                ?>&nbsp;</td>
<td colspan="8"></td>
              </tr>
             
<?php
  $rows = 1;
  if ($_REQUEST['by']=='companyname')
   {
  $specials_methods = "SELECT ". TABLE_ADDRESS_BOOK .".entry_company, " . TABLE_CUSTOMERS . ".customers_firstname, " . TABLE_CUSTOMERS . ".customers_lastname, " . TABLE_CUSTOMERS_GROUPS . ".customers_group_name, " . TABLE_CATEGORIES_DESCRIPTION . ".categories_name, " . TABLE_PRODUCTS_DESCRIPTION . ".products_name, " . TABLE_PRODUCTS_DESCRIPTION . ".products_description, " . TABLE_PRODUCTS . ".products_model, " . TABLE_PRODUCTS . ".products_model, " . TABLE_PRODUCTS . ".products_price, " . TABLE_PRODUCTS_GROUPS . ".customers_group_price
FROM ((((((" . TABLE_CUSTOMERS . " INNER JOIN ". TABLE_CUSTOMERS_GROUPS ." ON " . TABLE_CUSTOMERS . ".customers_group_id = " . TABLE_CUSTOMERS_GROUPS . ".customers_group_id) INNER JOIN ". TABLE_PRODUCTS_GROUPS ." ON " . TABLE_CUSTOMERS_GROUPS . ".customers_group_id = " . TABLE_PRODUCTS_GROUPS . ".customers_group_id) INNER JOIN " . TABLE_PRODUCTS . " ON " . TABLE_PRODUCTS_GROUPS . ".products_id = " . TABLE_PRODUCTS . ".products_id) INNER JOIN " . TABLE_PRODUCTS_DESCRIPTION . " ON " . TABLE_PRODUCTS . ".products_id = " . TABLE_PRODUCTS_DESCRIPTION . ".products_id) INNER JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " ON " . TABLE_PRODUCTS . ".products_id = " . TABLE_PRODUCTS_TO_CATEGORIES . ".products_id) INNER JOIN ". TABLE_ADDRESS_BOOK ." ON " . TABLE_CUSTOMERS . ".customers_id = ". TABLE_ADDRESS_BOOK .".customers_id) INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " ON " . TABLE_PRODUCTS_TO_CATEGORIES . ".categories_id = " . TABLE_CATEGORIES_DESCRIPTION . ".categories_id
ORDER BY ". TABLE_ADDRESS_BOOK .".entry_company";
  $specials_query = tep_db_query($specials_methods);
  
   } else  
   {
  
   $specials_methods = "SELECT ". TABLE_ADDRESS_BOOK .".entry_company, " . TABLE_CUSTOMERS . ".customers_firstname, " . TABLE_CUSTOMERS . ".customers_lastname, " . TABLE_CUSTOMERS_GROUPS . ".customers_group_name, " . TABLE_CATEGORIES_DESCRIPTION . ".categories_name, " . TABLE_PRODUCTS_DESCRIPTION . ".products_name, " . TABLE_PRODUCTS_DESCRIPTION . ".products_description, " . TABLE_PRODUCTS . ".products_model, " . TABLE_PRODUCTS . ".products_model, " . TABLE_PRODUCTS . ".products_price, " . TABLE_PRODUCTS_GROUPS . ".customers_group_price
FROM ((((((" . TABLE_CUSTOMERS . " INNER JOIN ". TABLE_CUSTOMERS_GROUPS ." ON " . TABLE_CUSTOMERS . ".customers_group_id = " . TABLE_CUSTOMERS_GROUPS . ".customers_group_id) INNER JOIN ". TABLE_PRODUCTS_GROUPS ." ON " . TABLE_CUSTOMERS_GROUPS . ".customers_group_id = " . TABLE_PRODUCTS_GROUPS . ".customers_group_id) INNER JOIN " . TABLE_PRODUCTS . " ON " . TABLE_PRODUCTS_GROUPS . ".products_id = " . TABLE_PRODUCTS . ".products_id) INNER JOIN " . TABLE_PRODUCTS_DESCRIPTION . " ON " . TABLE_PRODUCTS . ".products_id = " . TABLE_PRODUCTS_DESCRIPTION . ".products_id) INNER JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " ON " . TABLE_PRODUCTS . ".products_id = " . TABLE_PRODUCTS_TO_CATEGORIES . ".products_id) INNER JOIN ". TABLE_ADDRESS_BOOK ." ON " . TABLE_CUSTOMERS . ".customers_id = ". TABLE_ADDRESS_BOOK .".customers_id) INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " ON " . TABLE_PRODUCTS_TO_CATEGORIES . ".categories_id = " . TABLE_CATEGORIES_DESCRIPTION . ".categories_id
ORDER BY " . TABLE_PRODUCTS_DESCRIPTION . ".products_name";
}
  $specials_query = tep_db_query($specials_methods);
  
  while ($specials = tep_db_fetch_array($specials_query)) {
  

   
?>
<tr class="dataTableRow" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)">
	   
              <td class="dataTableContent" width="5%"><?php echo $specials['entry_company']; ?></td>
              <td class="dataTableContent" width="5%"><?php echo $specials['customers_firstname']?>&nbsp;&nbsp;<?php echo $specials['customers_lastname']; ?>
			  <td class="dataTableContent" width="5%"><?php echo $specials['customers_group_name']; ?></td>	
			  <td class="dataTableContent" width="20%"><?php echo $specials['categories_name']; ?></td>	
			  <td class="dataTableContent" width="20%"><?php echo $specials['products_name']; ?></td>	
			  <td class="dataTableContent" width="15%"><?php echo $specials['products_description']; ?></td>	
			  <td class="dataTableContent" width="5%"><?php echo $specials['products_model']; ?></td>	
  			  <td class="dataTableContent" width="5%"><?php echo $specials['products_price']; ?></td>	
			  <td class="dataTableContent" width="5%"><?php echo $specials['customers_group_price']; ?></td>				  
			
                <td class="dataTableContent" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'search=' . $specials['products_name'], 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>';  ?>&nbsp;</td>
				
				 
				

              </tr>
<?php
  }
?>
              <tr>
                <td colspan="10"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
  if (empty($action)) {
?>
                  <tr>
                    <td colspan="2" align="right"></td>
                  </tr>
<?php
  }
?>
                </table></td>
              </tr>
            </table></td>

          </tr>
        </table></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
